<!DOCTYPE HTML>
<html>
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
		<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    	<title>统战成员学习平台</title>
	    <link rel="stylesheet" type="text/css" href="../../css/base.css" />
	    <link rel="stylesheet" type="text/css" href="../../css/discovery.css" />
	</head>
	<body>
		<div id='app' class="paddt" style="display:none" v-show="true">
			<div class="update_form">
				<input type="text" v-model="usrEmail">
				<span><i class="icon_clear" @click="clear()"></i></span>
			</div>
		</div>
		<script type="text/javascript" src="../../script/api.js"></script>
		<script type="text/javascript" src="../../script/vue.min.js"></script>
		<script type="text/javascript" src="../../script/common.js"></script>
		<script type="text/javascript" src="../../script/layer_mobile/layer.js"></script>
		<script type="text/javascript">
		    new Vue({
				el: '#app',
		     	data: {
					userInfo:{},
					usrEmail: ''
		     	},
				watch: {
					usrEmail: function() {
			        	var $this = this;
						api.sendEvent({
						    name: 'toggle_btn_state',
						    extra: {
						        state: $this.usrEmail == $this.userInfo.usrEmail
						    }
						});
					}
				},
				mounted: function() {
		        	var $this = this;
		        	apiready = function() {
						api.parseTapmode();
						$this.init();
						api.addEventListener({
						    name: 'email_update_event'
						}, function(ret, err){
							$this.submit()
						});
                	}
		    	},
		    	methods: {
					init: function() {
						var $this = this;
						$this.userInfo = $api.getStorage(_.USERINFO) || {};
						$this.usrEmail = $this.userInfo.usrEmail;
					},
					clear: function () {
						var $this = this;
						$this.usrEmail = '';
					},
					submit: function () {
						var $this = this;
						if(!$this.usrEmail.length) {
							return msgUtil.toast({msg: '请输入邮箱'});
						}
						if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test($this.usrEmail)) {
							return msgUtil.toast({msg: '邮箱格式错误'});
						}
						post('/client/user/update', {
							usrImg: $this.userInfo.usrImg,
							usrPhone: $this.userInfo.usrPhone,
							usrEmail: $this.usrEmail
						},function (ret) {
							msgUtil.toast({msg: ret.message});
							if(ret.code == 200){
								$this.userInfo.usrEmail = $this.usrEmail;
								$api.setStorage(_.USERINFO, $this.userInfo);
								api.sendEvent({name:'refresh_userInfo_event'});
								setTimeout(function(){closeWin();},1000)
							}
						});
					}
		    	}
		    });
		</script>
	</body>
</html>
